#####################################################################
# Product:      KnowledgeEngine (Plone Edition)
#
# File:         Accessory.py
#
# Copyright:    Copyright (c) 2005, Faulkner Technologies
#
# Author:       Brian Oliver
#
# Description:  This file defines the Accessory interface,
#               which specifies the basic functionality of a 
#               mechanism that may be used to dynamically extend and
#               provide new features to Model builders for GenericObjects.
#
#               An Accessory is a pluggable wizard-like object designed to
#               enable the introduction of new KnowledgeEngine functionality 
#               on a GenericObject by GenericObject (class or instance) basis.  
#
#               Example Accessories include; ModelLockingAccessory,
#               MindManagerModelExportAccessory etc.
#
#               Accessories appear next to the property editor for 
#               GenericObjects (where appropriate).
#
# See Also:     GenericObject, ModelLockingAccessory
#####################################################################

#####################################################################
## KnowledgeEngine Library Imports
from Common import *
from SimpleWizard import SimpleWizard

#####################################################################
## Zope Library Imports
from Globals import InitializeClass
from AccessControl import ClassSecurityInfo
from AccessControl.Role import RoleManager
 
#####################################################################
## Python Library Imports
# (none)

#####################################################################
## Accessory Interface Definition
class Accessory(SimpleWizard):
    """
        An interface specifying the standard features of an Accessory
    """

    #---------------------------------------------------------------#

    #define security
    security = ClassSecurityInfo()
    security.declareObjectPublic()
    security.setDefaultAccess("allow")
        
    #---------------------------------------------------------------#

    def getIdentity(self):
        """
            ABSTRACT: Return the unique identity of the accessory
            in the Knowledge Engine
        """
        
        #typically this will be the same as the class name
        return "Accessory"
        
    #---------------------------------------------------------------#
        
    def getTitle(self, genericObject):
        """
            ABSTRACT: Returns the title of the Accessory (when
            applied to the specified genericObject)
            
            RETURN TYPE: String
        """

        return "Accessory"
        
    #---------------------------------------------------------------#
        
    def getPurpose(self, genericObject):
        """
            ABSTRACT: Returns the purpose of the Accessory (when
            applied to the specified genericObject)
            
            RETURN TYPE: String
        """

        return "Purpose"
        
    #---------------------------------------------------------------#
        
    def getIconName(self, genericObject):
        """
            ABSTRACT: Returns the name of the Icon of the Accessory (when
            applied to the specified genericObject).
            
            The IconName represents the image file name that will be found using
            acquisition.
            
            RETURN TYPE: String
        """

        return "wizard.wand.gif"
        
    #---------------------------------------------------------------#
        
    def getExecuteActionDisplayName(self, genericObject):
        """
            ABSTRACT: Returns the display name for the execute action of the Accessory (when
            applied to the specified genericObject)
            
            RETURN TYPE: String
        """

        return "Execute"
        
    #---------------------------------------------------------------#
        
    def isAvailableForGenericObject(self, genericObject):
        """
            ABSTRACT: Returns if the accessory is available for the 
            specified genericObject.
            
            This method is called to determine if an Accessory
            should be displayed for the specified genericObject 
            when rendering it's property editor etc.

            RETURN TYPE: Boolean
        """

        return false
        
    #---------------------------------------------------------------#
        
    def execute(self, genericObject, wizardState, request): 
        """
            Executes the accessory for the specified
            genericObject using the specified wizardState.
            
            OVERRIDE: This method if you require control of the
            returned HTTP response (via the request)
        """            

        #execute the accessory wizard with this object and the wizard state
        (success, message) = self.executeAccessoryWith(genericObject, wizardState)

        #now redirect back to this page with the messages
        return genericObject.GenericObject_accessories_form(genericObject, REQUEST=request, EDITINGOBJECT=genericObject, SUCCESS=success, MESSAGE=message)        
        
    #---------------------------------------------------------------#
        
    def executeAccessoryWith(self, genericObject, wizardState):
        """
            ABSTRACT: Executes the accessory for the specified
            genericObject, using the specified wizardState.            
            
            Returns a pair indicating the success of the accessory on
            the component and a corresponding message.
            
            RETURN TYPE: (Boolean, String)
        """
        
        return (true, "Successfully Applied Accessory")
        
    #---------------------------------------------------------------#

#####################################################################
## Class Initialisation
InitializeClass(Accessory)
